package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.StoreOperMapper;
import com.zhongyu.pojo.StoreOper;
import com.zhongyu.pojo.User;
import com.zhongyu.service.StoreOperService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.StoreOperVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service("storeOperService")
public class StoreOperServiceImpl  extends ServiceImpl<StoreOperMapper, StoreOper> implements StoreOperService {
    @Resource
   private StoreOperMapper storeOperMapper;
   /* @Override
    public List<StoreOper> searchAll() {
        return storeOperMapper.findAll();
    }*/

    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, StoreOperVo storeOperVo) {
        LambdaQueryWrapper<StoreOper> queryWrapper= Wrappers.<StoreOper>lambdaQuery();
        queryWrapper.eq(storeOperVo.getOperateId()!=null,StoreOper::getOperateId,storeOperVo.getOperateId())
                .ge(storeOperVo.getStartDate()!=null,StoreOper::getOperateTime,storeOperVo.getStartDate())
                .le(storeOperVo.getEndDate()!=null,StoreOper::getOperateTime,storeOperVo.getEndDate())
                .eq(storeOperVo.getStoreId()!=null,StoreOper::getStoreId,storeOperVo.getStoreId())
                .eq(storeOperVo.getGoodId()!=null,StoreOper::getGoodId,storeOperVo.getGoodId());
        Page page=new Page(pageNo,pageSize);
        List<StoreOper> list=storeOperMapper.findAll(page,queryWrapper);
//       System.out.println("==2>"+list.size());
        /* return PageResult.getInstanceByPage(page);*/
        return new PageResult(list,page.getTotal());

    }
}
